﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Windows.Forms
Imports Microsoft.Reporting.WebForms
Partial Class Form_frmReportAmlo
    Inherits System.Web.UI.Page

    Dim strSql As String
    Dim strRptType As String
    Dim strBranchCode As String
    Dim strDeptCode As String
    Dim strRptNo As String
    Dim strTypeDate As String
    Dim strStartDate As String
    Dim strEndDate As String
    Dim strSignType As String
    Dim strIsSent As String
    Dim strRptSubType As String
    Dim strTransType As String
    Dim UserRight As clsSessionMenuRight

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        'If Not (IsPostBack) Then
        '    hdfRPTTYPE.Value = Request.Item("rptType")
        'End If


        If Not (IsPostBack) Then
            hdfRPTTYPE.Value = Request.Item("RPTTYPE")
            hdfBRANCHCODE.Value = Request.Item("BRANCHCODE")
            hdfDEPTCODE.Value = Request.Item("DEPTCODE")
            hdfRPTNO.Value = Request.Item("RPTNO")
            hdfTYPEDATE.Value = Request.Item("TYPEDATE")
            hdfSTARTDATE.Value = Request.Item("STARTDATE")
            hdfENDDATE.Value = Request.Item("ENDDATE")
            hdfSIGNTYPE.Value = Request.Item("SIGNTYPE")
            hdfISSEND.Value = Request.Item("ISSEND")
            hdfRPTSUBTYPE.Value = Request.Item("RPTSUBTYPE")
            hdfTRANSTYPE.Value = Request.Item("TRANSTYPE")

            strRptType = Request.Item("RPTTYPE")
            strBranchCode = Request.Item("BRANCHCODE")
            strDeptCode = Request.Item("DEPTCODE")
            strRptNo = Request.Item("RPTNO")
            strTypeDate = Request.Item("TYPEDATE")
            strStartDate = Request.Item("STARTDATE")
            strEndDate = Request.Item("ENDDATE")
            strSignType = Request.Item("SIGNTYPE")
            If (strSignType = "2") Then
                strSignType = "0"
            End If

            strIsSent = Request.Item("ISSEND")
            strRptSubType = Request.Item("RPTSUBTYPE")
        Else
            If Not (IsCallback) Then
                strRptType = convertStringEncode(hdfRPTTYPE.Value)
                strBranchCode = convertStringEncode(hdfBRANCHCODE.Value)
                strDeptCode = convertStringEncode(hdfDEPTCODE.Value)
                strRptNo = convertStringEncode(hdfRPTNO.Value)
                strTypeDate = convertStringEncode(hdfTYPEDATE.Value)
                strStartDate = convertStringEncode(hdfSTARTDATE.Value)
                strEndDate = convertStringEncode(hdfENDDATE.Value)
                strSignType = convertStringEncode(hdfSIGNTYPE.Value)
                If (strSignType = "2") Then
                    strSignType = "0"
                End If
                strIsSent = convertStringEncode(hdfISSEND.Value)
                strRptSubType = convertStringEncode(hdfRPTSUBTYPE.Value)
                strTransType = convertStringEncode(hdfTRANSTYPE.Value)
            Else
                strRptType = (hdfRPTTYPE.Value)
                strBranchCode = (hdfBRANCHCODE.Value)
                strDeptCode = (hdfDEPTCODE.Value)
                strRptNo = (hdfRPTNO.Value)
                strTypeDate = (hdfTYPEDATE.Value)
                strStartDate = (hdfSTARTDATE.Value)
                strEndDate = (hdfENDDATE.Value)
                strSignType = (hdfSIGNTYPE.Value)
                If (strSignType = "2") Then
                    strSignType = "0"
                End If
                strIsSent = (hdfISSEND.Value)
                strRptSubType = (hdfRPTSUBTYPE.Value)
                strTransType = hdfTRANSTYPE.Value
            End If

        End If
        If (strRptType = "M51") Then
            printRptAmlo101()
        ElseIf (strRptType = "M52") Then
            printRptAmlo102()
        ElseIf (strRptType = "M53") Then
            printRptAmlo103()
        ElseIf (strRptType = "M57") Then
            If (strRptSubType = "1") Then
                printRptAmlo10509_1()
            ElseIf (strRptSubType = "2") Then
                printRptAmlo10509_2()
            Else
                printRptAmlo10509()
            End If
        End If
    End Sub

    Private Sub printRptAmlo101()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_01 = New Amlo1_01
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

        strSql = "SELECT     AMLO101.RPTSEQ,        AMLO101.RPTTYPE,          AMLO101.RPTYEAR, " _
                    & "      AMLO101.RPTNO,         AMLO101.RPTREV,           AMLO101.BRANCHCODE, " _
                    & "      AMLO101.DEPTCODE,      AMLO101.RPTDATE,          AMLO101.TRANSDATE, " _
                    & "      AMLO101.TRANSTYPE,     AMLO101.TRANSTYPEOTHER,   mtsctype1.TYPE_TSC_NAME TSCNAME, " _
                    & "      AMLO101.OBJBIZ, SBRANCH.BRANCHNAME ,SDEPARTMENT.DEPTNAME ," _
                    & "      AMLO101.OBJBIZOTHER,   AMLO101.SAVETYPE,         AMLO101.SAVEDATE, " _
                    & "      AMLO101.SIGNTYPE,      AMLO101.ISSEND,           AMLO101.SENDDATE, " _
                    & "      AMLO101.CREATEBY,      AMLO101.CREATEDATE,       AMLO101.UPDATEBY, " _
                    & "      AMLO101.UPDATEDATE,    AMLO101.ISSENDCONFIRM,    AMLODETAIL101.PREFIX, " _
                    & "      AMLODETAIL101.FIRSTNAME, AMLODETAIL101.MIDNAME,  AMLODETAIL101.LASTNAME, " _
                    & " AMLO101.ACCOUNTNO, AMLO101.TRANSAMT, AMLO101.CURRENCY " _
                    & " FROM         " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO101") & " " _
                    & "                     INNER JOIN " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL101") & " " _
                    & "                     ON AMLO101.RPTSEQ = AMLODETAIL101.RPTSEQ " _
                    & "                     left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE1") & " " _
                    & "                     on mtsctype1.TYPE_TSC_ID =amlo101.TRANSTYPE " _
                    & "                     left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on amlo101.DEPTCODE =  SDEPARTMENT.DEPTCODE " _
                    & "                     left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on amlo101.BRANCHCODE = SBRANCH.BRANCHCODE  " _
                    & "    where AMLODETAIL101.RPTIDX =1 and AMLO101.iscomplete=1"

        'If Not (strYear = "") Then
        '    strSql = strSql + " and " + "ADMIN.AMLO101.RPTYEAR =:RPTYEAR"
        'End If

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO101.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO101.TRANSDATE >= :STARTDATE and AMLO101.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO101.SAVEDATE >= :STARTDATE and AMLO101.SAVEDATE <= :ENDDATE "
            End If

        End If
        If Not (strSignType = "") Then
            strSql = strSql + " and " + "AMLO101.SIGNTYPE=:SIGNTYPE"
        End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO101.ISSEND=:ISSEND"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO101.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO101.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO101.CREATEBY=:CREATEBY"

        End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
        End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            End If
        End If

        If Not (strSignType = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
                                                     .valueColumn = strSignType}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
            End If
            
            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
            '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
        End If



        cls.rptAMLO101(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re



    End Sub

    Private Sub printRptAmlo102()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_02 = New Amlo1_02
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

         strSql = " SELECT     AMLO102.RPTSEQ,AMLO102.RPTTYPE,AMLO102.RPTYEAR,AMLO102.RPTNO,AMLO102.RPTREV, " _
               & "           AMLO102.BRANCHCODE,SBRANCH.BRANCHNAME ,AMLO102.DEPTCODE,SDEPARTMENT.DEPTNAME , " _
               & "           AMLO102.RPTDATE,AMLO102.TRANSDATE,AMLO102.TRANSTYPE,mtsctype2.TSCTYPENAME TSCNAME, " _
               & "           AMLO102.ASSETTYPE,MASSETTYPE.ASSETTYPE ASSETTYPENAME,AMLO102.TRANSTYPEOTHER, " _
               & "           AMLO102.OBJBIZ,AMLO102.OBJBIZOTHER,AMLO102.SAVETYPE,AMLO102.SAVEDATE, " _
               & "           AMLO102.SIGNTYPE,AMLO102.ISSEND,AMLO102.SENDDATE, " _
               & "           AMLO102.CREATEBY,AMLO102.CREATEDATE,AMLO102.UPDATEBY,AMLO102.UPDATEDATE, " _
               & "           AMLO102.ISSENDCONFIRM,AMLODETAIL102.PREFIX,AMLODETAIL102.FIRSTNAME,AMLODETAIL102.MIDNAME, " _
               & "           AMLODETAIL102.LASTNAME,AMLO102.ACCOUNTNO, AMLO102.TRANSAMT, AMLO102.CURRENCY  " _
               & " FROM       " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO102") & " INNER JOIN " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL102") & "  " _
               & "                            ON AMLO102.RPTSEQ = AMLODETAIL102.RPTSEQ " _
               & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE2") & " on amlo102.TRANSTYPE =  mtsctype2.TSCTYPEID " _
               & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableMASSETTYPE") & " on amlo102.ASSETTYPE =  MASSETTYPE.ASSETTYPEID " _
               & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on amlo102.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
               & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on amlo102.BRANCHCODE = SBRANCH.BRANCHCODE  " _
               & " where AMLODETAIL102.RPTIDX =1 and AMLO102.iscomplete=1 "

       

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO102.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO102.TRANSDATE >= :STARTDATE and AMLO102.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO102.SAVEDATE >= :STARTDATE and AMLO102.SAVEDATE <= :ENDDATE "
            End If

        End If
        If Not (strSignType = "") Then
            strSql = strSql + " and " + "AMLO102.SIGNTYPE=:SIGNTYPE"
        End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO102.ISSEND=:ISSEND"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO102.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO102.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO102.CREATEBY=:CREATEBY"

        End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
        End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            End If
        End If

        If Not (strSignType = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
                                                     .valueColumn = strSignType}
            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
            End If

            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
            '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
        End If



        cls.rptAMLO102(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re



    End Sub

    Private Sub printRptAmlo103()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_03 = New Amlo1_03
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

        strSql = " SELECT     AMLO103.RPTSEQ,AMLO103.RPTTYPE,AMLO103.RPTYEAR,AMLO103.RPTNO, " _
               & "           AMLO103.RPTREV, AMLO103.BRANCHCODE, AMLO103.DEPTCODE, SBRANCH.BRANCHNAME , " _
               & "           SDEPARTMENT.DEPTNAME ,AMLO103.RPTDATE,AMLO103.TRANSDATE, AMLO103.TRANSTYPE, " _
               & "           AMLO103.TRANSTYPEOTHER, mtsctype3.TSCTYPENAME TSCNAME,AMLO103.OBJBIZ, " _
               & "           AMLO103.OBJBIZOTHER, AMLO103.SAVETYPE, AMLO103.SAVEDATE, AMLO103.SIGNTYPE, " _
               & "           AMLO103.ISSEND, AMLO103.SENDDATE, AMLO103.CREATEBY, AMLO103.CREATEDATE, " _
               & "           AMLO103.UPDATEBY, AMLO103.UPDATEDATE, AMLO103.ISSENDCONFIRM, AMLODETAIL103.PREFIX, " _
               & "           AMLODETAIL103.FIRSTNAME, AMLODETAIL103.MIDNAME, AMLODETAIL103.LASTNAME ,AMLO103.ACCOUNTNO, " _
               & "           AMLO103.TRANSAMT, AMLO103.CURRENCY ,AMLO103.DOCREF " _
               & " FROM       " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO103") & " INNER JOIN " _
               & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL103") & " ON AMLO103.RPTSEQ = AMLODETAIL103.RPTSEQ " _
               & "                        left join " _
               & "                       " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE3") & " on mtsctype3.TSCTYPEID = AMLO103.TRANSTYPE " _
               & "                        left join " _
               & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on AMLO103.DEPTCODE =  SDEPARTMENT.DEPTCODE " _
               & "                        left join " _
               & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on AMLO103.BRANCHCODE = SBRANCH.BRANCHCODE " _
               & " where AMLODETAIL103.RPTIDX =1 and AMLO103.iscomplete=1 "



        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO103.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO103.TRANSDATE >= :STARTDATE and AMLO103.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO103.SAVEDATE >= :STARTDATE and AMLO103.SAVEDATE <= :ENDDATE "
            End If

        End If
        'If Not (strSignType = "") Then
        '    strSql = strSql + " and " + "AMLO103.SIGNTYPE=:SIGNTYPE"
        'End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO103.ISSEND=:ISSEND"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO103.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO103.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO103.CREATEBY=:CREATEBY"

        End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
        End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            End If
        End If

        'If Not (strSignType = "") Then
        '    clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
        '                                             .valueColumn = strSignType}
        '    colVarParameter.Add(clsVarParameter)
        'End If
        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
            End If

            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
            '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
        End If



        cls.rptAMLO103(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re



    End Sub

    Private Sub printRptAmlo10509()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_05_9 = New Amlo1_05_9
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

        'strSql = " SELECT AMLO1059.DCN_DOCUMENTNO, SBRANCH.BRANCHCODE, SBRANCH.BRANCHNAME, SBRANCH.DEPTCODE, SDEPARTMENT.DEPTNAME, SZONE.ZONECODE, SZONE.ZONENAME, " _
        '    & "           AMLO1059.P3_TRANS_DATE, MTSCTYPE_1_05_9.TSCTYPENAME, AMLO1059.P3_TRAN_AMT, " _
        '    & "           AMLO1059.P3_CUST_NAME, AMLO1059.P3_FORACID, AMLO1059.P3_CUST_NAME2, AMLO1059.P3_FORACID2, " _
        '    & "           AMLO1059.P3_TRAN_CODE " _
        '    & "     FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059") _
        '    & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE_1_05_9") & " on mtsctype_1_05_9.TSCTYPEID = amlo1059.key_flg " _
        '    & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & "  on AMLO1059.Init_Sol_Id = SBRANCH.Sol_Id  " _
        '    & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & "  on SBRANCH.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
        '    & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & "  on SZONE.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
        '    & "           where(AMLO1059.ISCOMPLETE = 1) "

        strSql = " SELECT AMLO1059.DCN_DOCUMENTNO, SBRANCH.BRANCHCODE, SBRANCH.BRANCHNAME, SBRANCH.DEPTCODE, SDEPARTMENT.DEPTNAME, SZONE.ZONECODE, " _
            & "     SZONE.ZONENAME, AMLO1059.P3_TRANS_DATE, MTSCTYPE_1_05_9.TSCTYPENAME, AMLO1059.P3_TRAN_AMT, AMLO1059.P3_CUST_NAME, " _
            & "     AMLO1059.P3_FORACID, AMLO1059.P3_CUST_NAME2, AMLO1059.P3_FORACID2, AMLO1059.P3_TRAN_CODE, SBRANCH.SOL_ID, AMLO1059.KEY_FLG, " _
            & "     AMLO1059.P2_FORACID2, AMLO1059.P2_CUST_FNAME2, AMLO1059.P2_SALUTATION2, AMLO1059.P2_CUST_MNAME2, AMLO1059.P2_CUST_LNAME2, " _
            & "     AMLO1059.P2_HOME2_NO, AMLO1059.P2_HOME2_ADDRESS, AMLO1059.P2_HOME2_CITY, AMLO1059.P2_HOME2_STATE, AMLO1059.P2_HOME2_COUNTRY, " _
            & "     AMLO1059.P2_HOME2_ZIP, AMLO1059.P2_HOME2_NATION, AMLO1059.P2_CITIZEN_ID2, AMLO1059.P2_CITIZEN_OPN_BY2, AMLO1059.P2_CITIZEN_OPN2, " _
            & "     AMLO1059.P2_CITIZEN_EXPIRED2, AMLO1059.P2_SALUTATION, AMLO1059.P2_CUST_FNAME, AMLO1059.P2_CUST_MNAME, AMLO1059.P2_CUST_LNAME, " _
            & "     AMLO1059.P2_HOME_ADDRESS, AMLO1059.P2_HOME_CITY, AMLO1059.P2_HOME_STATE, AMLO1059.P2_HOME_COUNTRY, AMLO1059.P2_HOME_ZIP, " _
            & "     AMLO1059.P2_HOME_NATION, AMLO1059.P2_CITIZEN_ID, AMLO1059.P2_CITIZEN_OPN_BY, AMLO1059.P2_CITIZEN_OPN, AMLO1059.P2_CITIZEN_EXPIRED " _
            & "     FROM        " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059") & " AMLO1059 LEFT OUTER JOIN " _
            & "                 " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE_1_05_9") & " MTSCTYPE_1_05_9 ON mtsctype_1_05_9.TSCTYPEID = amlo1059.key_flg LEFT OUTER JOIN " _
            & "                 " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " SBRANCH ON AMLO1059.INIT_SOL_ID = SBRANCH.SOL_ID LEFT OUTER JOIN " _
            & "                 " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " SDEPARTMENT ON SBRANCH.DEPTCODE = SDEPARTMENT.DEPTCODE LEFT OUTER JOIN " _
            & "                 " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & " SZONE ON SZONE.DEPTCODE = SDEPARTMENT.DEPTCODE " _
            & "WHERE        (1 = 1)"

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO1059.DCN_DOCUMENTNO=:RPTNO"
            End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO1059.P3_TRANS_DATE >= :STARTDATE and AMLO1059.P3_TRANS_DATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO1059.CREATEDATE >= :STARTDATE and AMLO1059.CREATEDATE <= :ENDDATE "
                End If

            End If
            'If Not (strSignType = "") Then
            '    strSql = strSql + " and " + "AMLO103.SIGNTYPE=:SIGNTYPE"
            'End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO1059.ISSEND=:ISSEND"
            End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.DEPTCODE=:DEPTCODE"
            End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.BRANCHCODE=:BRANCHCODE"
            End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
                ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
                ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
                'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO1059.CREATEBY=:CREATEBY"

            End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
            End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
                End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
                End If
            End If

            'If Not (strSignType = "") Then
            '    clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
            '                                             .valueColumn = strSignType}
            '    colVarParameter.Add(clsVarParameter)
            'End If
        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
                End If

            colVarParameter.Add(clsVarParameter)
            End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
            End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
            End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
                '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
                '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
                '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
                '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
            End If


        cls.rptAMLO1059(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re
    End Sub

    Private Sub printRptAmlo10509_1()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_05_9_s1 = New Amlo1_05_9_s1
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

        strSql = " SELECT AMLO1059.DCN_DOCUMENTNO, SBRANCH.BRANCHCODE, SBRANCH.BRANCHNAME, SBRANCH.DEPTCODE, SDEPARTMENT.DEPTNAME, SZONE.ZONECODE, SZONE.ZONENAME, " _
            & "           AMLO1059.KEY_FLG, AMLO1059.P3_TRANS_DATE, MTSCTYPE_1_05_9.TSCTYPENAME, AMLO1059.P3_TRAN_AMT, " _
            & "           AMLO1059.P3_CUST_NAME, AMLO1059.P3_FORACID, AMLO1059.P3_CUST_NAME2, AMLO1059.P3_FORACID2, " _
            & "           AMLO1059.P3_TRAN_CODE, " _
            & "           AMLO1059.ISCONFIRM, AMLO1059.ISDELETE, AMLO1059.ISSEND " _
            & "     FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059") _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE_1_05_9") & " on mtsctype_1_05_9.TSCTYPEID = amlo1059.key_flg " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & "  on AMLO1059.Init_Sol_Id = SBRANCH.Sol_Id  " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & "  on SBRANCH.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & "  on SZONE.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
            & "           where(1 = 1) "

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO1059.DCN_DOCUMENTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO1059.P3_TRANS_DATE >= :STARTDATE and AMLO1059.P3_TRANS_DATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO1059.CREATEDATE >= :STARTDATE and AMLO1059.CREATEDATE <= :ENDDATE "
            End If

        End If
        'If Not (strSignType = "") Then
        '    strSql = strSql + " and " + "AMLO103.SIGNTYPE=:SIGNTYPE"
        'End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO1059.ISSEND=:ISSEND"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO1059.CREATEBY=:CREATEBY"

        End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
        End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            End If
        End If

        'If Not (strSignType = "") Then
        '    clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
        '                                             .valueColumn = strSignType}
        '    colVarParameter.Add(clsVarParameter)
        'End If
        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
            End If

            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
            '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
        End If


        cls.rptAMLO1059_s1(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re
    End Sub

    Private Sub printRptAmlo10509_2()
        Dim ds As New dsAmloReport
        Dim cls As New clsConnToDbByReport
        Dim re As Amlo1_05_9_s2 = New Amlo1_05_9_s2
        Dim colVarParameter As Collection = New Collection
        Dim strPrmCondition As String = ""
        Dim clsVarParameter As clsVariable
        Dim clsFormatDate As New clsDateFormat
        Dim strDateStart As String = ""
        Dim strDateEnd As String = ""
        UserRight = Session("clsMenuRight")

        strSql = " SELECT AMLO1059.DCN_DOCUMENTNO, SBRANCH.BRANCHCODE, SBRANCH.BRANCHNAME, SBRANCH.DEPTCODE, SDEPARTMENT.DEPTNAME, SZONE.ZONECODE, SZONE.ZONENAME, " _
            & "           AMLO1059.P3_TRANS_DATE, MTSCTYPE_1_05_9.TSCTYPENAME, AMLO1059.P3_TRAN_AMT, " _
            & "           AMLO1059.P3_CUST_NAME, AMLO1059.P3_FORACID, AMLO1059.P3_CUST_NAME2, AMLO1059.P3_FORACID2, " _
            & "           AMLO1059.KEY_FLG, AMLO1059.P3_TRAN_CODE, MTSCTYPE_1_05_9.TSCTYPENAME, MTSCTYPE_1_05_9.TSCMETHOD, " _
            & "           AMLO1059.P3_HOME_ADDRESS, AMLO1059.P3_MAIL_ADDRESS, " _
            & "           AMLO1059.P2_WORK2_NO, AMLO1059.P2_WORK2_ADDRESS, AMLO1059.P2_WORK2_CITY, AMLO1059.P2_WORK2_STATE, AMLO1059.P2_WORK2_COUNTRY, " _
            & "           AMLO1059.P2_WORK2_ZIP, AMLO1059.P2_WORK2_NATION, " _
            & "           AMLO1059.P3_HOME_ADDRESS2, AMLO1059.P3_MAIL_ADDRESS2, " _
            & "           AMLO1059.P2_WORK2_ADDRESS ||' '|| AMLO1059.P2_WORK2_CITY ||' '|| AMLO1059.P2_WORK2_STATE ||' '|| AMLO1059.P2_WORK2_COUNTRY " _
            & "           ||' '|| AMLO1059.P2_WORK2_ZIP ||' '|| AMLO1059.P2_WORK2_NATION AS P3_WORK_ADDRESS, " _
            & "           AMLO1059.P2_WORK_NO, AMLO1059.P2_WORK_ADDRESS, AMLO1059.P2_WORK_CITY, AMLO1059.P2_WORK_STATE, AMLO1059.P2_WORK_COUNTRY, " _
            & "           AMLO1059.P2_WORK_ZIP, AMLO1059.P2_WORK_NATION, " _
            & "           AMLO1059.P2_WORK_ADDRESS ||' '|| AMLO1059.P2_WORK_CITY ||' '|| AMLO1059.P2_WORK_STATE ||' '|| AMLO1059.P2_WORK_COUNTRY " _
            & "           ||' '|| AMLO1059.P2_WORK_ZIP ||' '|| AMLO1059.P2_WORK_NATION AS P3_WORK_ADDRESS2, " _
            & "           ACID_FROM.SALUTATION || ACID_FROM.CUST_FNAME || ' ' || ACID_FROM.CUST_MNAME || ' ' || ACID_TO.CUST_LNAME AS ACID_FROM_NAME, " _
            & "           ACID_FROM.CITIZEN_ID AS ACID_FROM_CITIZEN_ID, ACID_FROM.CITIZEN_OPN AS ACID_FROM_CITIZEN_OPN, ACID_FROM.CITIZEN_EXPIRED AS ACID_FROM_CITIZEN_EXP, " _
            & "           ACID_TO.SALUTATION || ACID_TO.CUST_FNAME || ' ' || ACID_TO.CUST_MNAME || ' ' || ACID_TO.CUST_LNAME AS ACID_TO_NAME, " _
            & "           ACID_TO.CITIZEN_ID AS ACID_TO_CITIZEN_ID, ACID_TO.CITIZEN_OPN AS ACID_TO_CITIZEN_OPN, ACID_TO.CITIZEN_EXPIRED AS ACID_TO_CITIZEN_EXP, " _
            & "           AMLO1059.ISCONFIRM, AMLO1059.ISDELETE, AMLO1059.ISSEND " _
            & "     FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059") _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE_1_05_9") & " on mtsctype_1_05_9.TSCTYPEID = amlo1059.key_flg " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & "  on AMLO1059.Init_Sol_Id = SBRANCH.Sol_Id " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & "  on SBRANCH.DEPTCODE =  SDEPARTMENT.DEPTCODE " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & "  on SZONE.DEPTCODE = SDEPARTMENT.DEPTCODE " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059_ACID_FROM") & "  ACID_FROM on ACID_FROM.ACID = AMLO1059.FROM_ACID AND ACID_FROM.TRAN_DATE = AMLO1059.P3_TRANS_DATE " _
            & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO1059_ACID_TO") & "  ACID_TO on ACID_TO.ACID = AMLO1059.TO_ACID AND ACID_TO.TRAN_DATE = AMLO1059.P3_TRANS_DATE " _
            & "           where(1 = 1) "

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO1059.DCN_DOCUMENTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO1059.P3_TRANS_DATE >= :STARTDATE and AMLO1059.P3_TRANS_DATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO1059.CREATEDATE >= :STARTDATE and AMLO1059.CREATEDATE <= :ENDDATE "
            End If

        End If
        'If Not (strSignType = "") Then
        '    strSql = strSql + " and " + "AMLO103.SIGNTYPE=:SIGNTYPE"
        'End If
        If Not (strIsSent = "") Then
            strSql = strSql + " and " + "AMLO1059.ISSEND=:ISSEND"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "SBRANCH.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            ' strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            'strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO1059.CREATEBY=:CREATEBY"

        End If

        If Not (strRptNo = "") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "RPTNO", _
                                                      .valueColumn = strRptNo}
            colVarParameter.Add(clsVarParameter)
        End If


        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            strDateStart = dteStartDate.ToShortDateString
            strDateEnd = dteEndDate.ToShortDateString
            clsVarParameter = New clsVariable() With {.nameColumn = "STARTDATE", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "ENDDATE", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            End If
        End If

        'If Not (strSignType = "") Then
        '    clsVarParameter = New clsVariable() With {.nameColumn = "SIGNTYPE", _
        '                                             .valueColumn = strSignType}
        '    colVarParameter.Add(clsVarParameter)
        'End If
        If Not (strIsSent = "") Then
            If strIsSent = "1" Then
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                    .valueColumn = strIsSent}
            Else
                clsVarParameter = New clsVariable() With {.nameColumn = "ISSEND", _
                                                        .valueColumn = 0}
            End If

            colVarParameter.Add(clsVarParameter)
        End If

        If Not (strDeptCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                   .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)
        End If
        If Not (strBranchCode = "0") Then
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                   .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            '.SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
            '.SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
            clsVarParameter = New clsVariable() With {.nameColumn = "CREATEBY", _
                                              .valueColumn = UserRight.getUserName}
            colVarParameter.Add(clsVarParameter)
        End If


        cls.rptAMLO1059_s2(re, strSql, ds, colVarParameter)
        re.prmStartDate.Value = strDateStart
        re.prmEndDate.Value = strDateEnd

        ReportViewer1.Report = re
    End Sub

    Private Function convertStringEncode(ByVal strCon As String) As String
        Dim rtStr As String = ""
        Try
            rtStr = Encoding.UTF8.GetString(Encoding.GetEncoding("tis-620").GetBytes(strCon))
        Catch ex As Exception
            Throw ex
        End Try
        Return rtStr
    End Function
End Class
